package com.pengcheng.taskapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.pengcheng.taskapplication.R;
import com.pengcheng.taskapplication.model.CarModel;

import java.util.List;

public class CarAdapterNew extends BaseAdapter {

	Context context;
	LayoutInflater inflater;
	List<CarModel> carModels;
	private String type;
	int last_item;
	private int selectedPosition = -1;
	public CarAdapterNew(Context context, List<CarModel> carModels,String type){
		this.context = context;
		this.carModels = carModels;
		this.type     = type;
		inflater= LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return carModels.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return carModels.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder  holder = null;
		if(convertView==null){
			convertView = inflater.inflate(R.layout.activity_bz_list_item, null);
			holder = new ViewHolder();
			holder.tv_plate =(TextView)convertView.findViewById(R.id.tv_plate);
			holder.tv_e_plate=(TextView)convertView.findViewById(R.id.tv_e_plate);
			holder.ll_bg=(LinearLayout)convertView.findViewById(R.id.ll_bg);
			convertView.setTag(holder);
		}
		else{
			holder=(ViewHolder)convertView.getTag();
		}

		CarModel model= carModels.get(position);
		holder.tv_e_plate.setText(model.getEcardCode());
		holder.tv_plate.setText(model.getPlateNo());
//		holder.tv_plate_no.setText("车牌: "+model.getPlateNo());
		if(type.equals("1")){
			holder.ll_bg.setBackgroundResource(R.drawable.jianyan);
		}else if(type.equals("2")) {
			holder.ll_bg.setBackgroundResource(R.drawable.dianzi);
		}

		return convertView;
	}

	public static class ViewHolder{
		public TextView tv_plate;
		public TextView tv_e_plate;
		public LinearLayout ll_bg;

	}

	public void setSelectedPosition(int position) {
		selectedPosition = position;
	}

}
